BookingDonationView = function() {
	//console.log(this);
	bookingDonationViewThis = this;
	//클래스에서 사용하는 this
	bookingDonationViewThis.bookingDonationViewJson=null;
	//클래스에서 사용하는 jsonData
	bookingDonationViewThis._HTMLDom = null;
}
BookingDonationView.prototype = {
	donationDetailView : function() {
		var mj = new MJson();
		var cm = new ConnectionManager();
		
		mj.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
		mj.putPub(MJson.PUB.SID, "DR001");
		mj.putPub(MJson.PUB.SERVICENAME, "DonationDetailView");

		mj.putParameter("reserveSeq", document.globalObj.DONATION_DATA.donation_seq);

		console.log("request : " + mj.getJsonString());
		cm.requestGet(mj.getJsonString(), function(jsonData) {
			console.log("성공 :: 통신");

			if (mj.checkServiceResult(jsonData)) {
				console.log("success :: " + JSON.stringify(jsonData));
				bookingDonationViewThis.bookingDonationViewJson=jsonData
				//console.log('donationMainReserveList :: 성공');

				//------- UI Display -------//
				var donationHeader = bookingDonationViewThis._HTMLDom.donationHeader;
				var donationHeaderDt = bookingDonationViewThis._HTMLDom.donationHeaderDt;
				var donationHeaderDd = bookingDonationViewThis._HTMLDom.donationHeaderDd;

				var applicationDate = '<em>신청기간  :</em>' + jsonData.msp.contents.items.startDt + "~" + jsonData.msp.contents.items.endDt;
				donationHeaderDt.find('p:eq(0)').html(applicationDate);

				var publicDate = (jsonData.msp.contents.items.publicDate ? jsonData.msp.contents.items.publicDate : jsonData.msp.contents.items.reservDate)
				var publicationDate = '<em>당첨자발표  :</em>' + publicDate;
				donationHeaderDt.find('p:eq(1)').html(publicationDate);

				var holeCount = new String(jsonData.msp.contents.items.holeCnt);
				var donationTitle = jsonData.msp.contents.items.courseInfoNm + '<em>' + holeCount.slice(0, (holeCount.length - 1)) + 'H</em>';
				donationHeaderDd.find('h5').html(donationTitle);

				var donationRoundDate = '<em>라운드날짜</em>' + jsonData.msp.contents.items.reservDate + '(' + jsonData.msp.contents.items.bookingDay + ')';
				donationHeaderDd.find('li:eq(0)').html(donationRoundDate);

				var teaTime = '<em>티타임</em>' + jsonData.msp.contents.items.bookingTime;
				donationHeaderDd.find('li:eq(1)').html(teaTime);

				var fee = addPeriod(jsonData.msp.contents.items.greenFee);
				var greenFee = '<em>1인 그린피</em><mark>￦' + fee + '</mark>';
				donationHeaderDd.find('li:eq(2)').html(greenFee);

				donationHeader.append(donationHeaderDt);
				donationHeader.append(donationHeaderDd);

				var donationContents = bookingDonationViewThis._HTMLDom.donationContents;
				var donationContentsDt = bookingDonationViewThis._HTMLDom.donationContentsDt;
				var donationContentsDd1 = bookingDonationViewThis._HTMLDom.donationContentsDd1;
				var donationContentsDd2 = bookingDonationViewThis._HTMLDom.donationContentsDd2;
				var donationContentsDd3 = bookingDonationViewThis._HTMLDom.donationContentsDd3;

				var applyCount = '참여 :<mark>' + addPeriod(jsonData.msp.contents.items.applyCnt) + '</mark>명';
				donationContentsDt.find('span:first').html(applyCount);

				var applyCount = '참여 :<mark>' + addPeriod(jsonData.msp.contents.items.applyCnt) + '</mark>명';
				var totalGreenFee = jsonData.msp.contents.items.toTalgreenFee ? jsonData.msp.contents.items.toTalgreenFee : 0;
				var currentPercent = (totalGreenFee / 5000000) * 100;
				donationContentsDd1.find('p:eq(2)').find('span:eq(0)').attr("style", "width:" + currentPercent + "%;");
				donationContentsDd1.find('p:eq(2)').find('span:eq(1)').html(totalGreenFee);

				var donatePrice = '응모 <mark>￦ ' + addPeriod(jsonData.msp.contents.items.donatePrice) + '</mark>';
				donationContentsDd2.html(donatePrice);
				
				 
				donationContents.append(donationContentsDt);
				donationContents.append(donationContentsDd1);
				donationContents.append(donationContentsDd2);
				donationContents.append(donationContentsDd3);
				//--------------------------//
				bookingDonationViewThis.didLoadObjects();
				//UI객체 
			} else {
				console.log('donationMainReserveList :: 실패');
			}
		}, function(e) {
			console.log("실패 :: 통신");
		});
	},

	onPageShow : function() {
		console.log(this);
		var donationHeader = $("#donation_header");
		var donationHeaderDt = donationHeader.find("dt:first");
		var donationHeaderDd = donationHeader.find("dd:first");

		var donationContents = $("#donation_contents");
		var donationContenstDt = donationContents.find('dt:first');
		var donationContentsDd1 = donationContents.find('dd:eq(0)');
		var donationContentsDd2 = donationContents.find('dd:eq(1)');
		var donationContentsDd3 = donationContents.find('dd:eq(2)');
		
		var donationFooter = $("#donation_footer");
		donationFooter.find('ul > li:eq(0)').bind('click', function(event) {
			$.mobile.changePage('booking_view_guide.html');
		});
		donationFooter.find('ul > li:eq(1)').bind('click', function(event) {
			$.mobile.changePage('booking_view_course.html');
		});
		donationFooter.find('ul > li:eq(2)').bind('click', function(event) {
			$.mobile.changePage('booking_view_price.html');
		});
	
		bookingDonationViewThis._HTMLDom = {
			"donationHeader" : donationHeader,
			"donationHeaderDt" : donationHeaderDt,
			"donationHeaderDd" : donationHeaderDd,
			"donationContents" : donationContents,
			"donationContentsDt" : donationContenstDt,
			"donationContentsDd1" : donationContentsDd1,
			"donationContentsDd2" : donationContentsDd2,
			"donationContentsDd3" : donationContentsDd3
		}
		donationHeader.empty();
		donationContents.empty();
		bookingDonationViewThis.donationDetailView();
		
		$("#donation_view_reserv_btn").bind('click', function(event) {
		  console.log('test');
		});
	},
	didLoadObjects : function() {
		bookingDonationViewThis._HTMLDom.donationContentsDd3.find('a').bind('click', function(event) {
			$.mobile.changePage('donation_offer_popup.html');
		});
		$("#goBookingViewCourse").bind('click', function(event) {
			if (bookingDonationViewThis.bookingDonationViewJson.msp.contents.items.reserveSeq) {
				document.globalObj.BOOKING_DATA.courseInfo.reserv_id = bookingDonationViewThis.bookingDonationViewJson.msp.contents.items.reserveSeq;
				$.mobile.changePage('booking_view_course.html');
			}
		});
		$("#goBookingViewPrice").bind('click', function(event) {
			if (bookingDonationViewThis.bookingDonationViewJson.msp.contents.items.reserveSeq) {
				document.globalObj.BOOKING_DATA.coursePrice.reserv_id = bookingDonationViewThis.bookingDonationViewJson.msp.contents.items.reserveSeq;
				$.mobile.changePage('booking_view_price.html');
			}
		});
	}
}
function addPeriod(nStr) {
	nStr += '';
	x = nStr.split(',');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}